package com.nulldev.util.web.nCaptcha.captchas.obftext;

import java.awt.image.BufferedImage;

import com.nulldev.util.image.ImageUtil;
import com.nulldev.util.image2.textobf.TextObf;
import com.nulldev.util.image2.textobf.TextObf.ObfuscationMethod;
import com.nulldev.util.java.DataSet;
import com.nulldev.util.math.MathUtil;
import com.nulldev.util.string.StringsUtil;
import com.nulldev.util.web.nCaptcha.backend.Captcha;

public class MathCaptcha implements Captcha {

	@Override
	public DataSet<String, String[]> generateBase64Image(int botLevel) {
		// polishing my 11+4's
		final int i0 = MathUtil.randInt(1, 11);
		final int i1 = MathUtil.randInt(1, 11);
		final BufferedImage obf = TextObf.obfuscate(i0 + " + " + i1 + " = ?"
				, (botLevel > 1 ? ObfuscationMethod.DualPixelObfuscation : ObfuscationMethod.PixelObfuscation));
		final String base64 = ImageUtil.encodeToString(obf, "png");
		return new DataSet<String, String[]>("data:image/png;base64," + base64, new String[] {
				String.valueOf(i0 + i1),
				String.valueOf(i0 + i1) + ".0"});
	}

	@Override
	public String getType() {
		return "math";
	}

}
